typedef int Datatype;
typedef struct {
	Datatype *arry;
	int front;
	int back;
	int size;
	int capicity;
} MyCircularQueue;

bool myCircularQueueIsEmpty(MyCircularQueue* obj);
bool myCircularQueueIsFull(MyCircularQueue* obj);

MyCircularQueue* myCircularQueueCreate(int k) {
	MyCircularQueue *obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
	if (obj == NULL)
	{
		return NULL;
	}
	obj->arry = (Datatype*)malloc(sizeof(Datatype)*k);
	if (obj->arry == NULL)
	{
		return NULL;
	}
	obj->front = 0;
	obj->back = 0;
	obj->size = 0;
	obj->capicity = k;
	return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
	bool ret = true;
	if (myCircularQueueIsFull(obj) == true)
	{
		ret = false;
	}
	else
	{
		obj->arry[obj->back] = value;
		if (obj->back == (obj->capicity - 1))
		{
			obj->back = 0;
		}
		else
		{
			obj->back++;
		}
		ret = true;
		obj->size++;
	}
	return ret;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
	bool ret = true;
	if (myCircularQueueIsEmpty(obj) == true)
	{
		ret = false;
	}
	else
	{
		if (obj->front == (obj->capicity - 1))
		{
			obj->front = 0;
		}
		else
		{
			obj->front++;
		}
		ret = true;
		obj->size--;
	}
	return ret;
}

int myCircularQueueFront(MyCircularQueue* obj) {
	int ret = 0;
	if (myCircularQueueIsEmpty(obj) == true)
	{
		ret = -1;
	}
	else
	{
		return obj->arry[obj->front];
	}
	return ret;
}

int myCircularQueueRear(MyCircularQueue* obj) {
	int ret = 0;
	if (myCircularQueueIsEmpty(obj) == true)
	{
		ret = -1;
	}
	else
	{
		if (obj->back == 0)
		{
			return obj->arry[obj->capicity - 1];
		}
		else
		{
			return obj->arry[obj->back - 1];
		}
	}
	return ret;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
	bool ret = true;
	if (obj->size == 0)
	{
		ret = true;
	}
	else
	{
		ret = false;
	}
	return ret;

}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
	bool ret = true;
	if (obj->size == obj->capicity)
	{
		ret = true;
	}
	else
	{
		ret = false;
	}
	return ret;
}

void myCircularQueueFree(MyCircularQueue* obj) {
	free(obj->arry);
	free(obj);
}